package bottlepacker.view;
import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.Toolkit;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.JPopupMenu;

import bottlepacker.model.Bottle;

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Label;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;


public class SixPack extends JFrame {

	//ArrayList of Bottles
	ArrayList<Bottle> myPack = new ArrayList<Bottle>();

	// The number of cokes when a order is placed
	int numCokesOrdered = 0;

	// The number of sprites when a order is placed
	int numSpritesOrdered = 0;

	//Number of cokes available
	int cokesAvailable;

	//Number of sprites available
	int spritesAvailable;

	//Num of drinks available
	int numDrinks = 0;

	//initialized order number 1
	int orderNum = 1;



	/**************************************************************************************************************************************
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SixPack frame = new SixPack();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}


	/**
	 * Constructor
	 */
	public SixPack() {

		//Creating the Bottles
		final Bottle b1 = new Bottle(1, "none");
		final Bottle b2 = new Bottle(2, "none");
		final Bottle b3 = new Bottle(3, "none");
		final Bottle b4 = new Bottle(4, "none");
		final Bottle b5 = new Bottle(5, "none");
		final Bottle b6 = new Bottle(6, "none");

		//Adding the bottles to the array list
		myPack.add(b1); 
		myPack.add(b2); 
		myPack.add(b3); 
		myPack.add(b4); 
		myPack.add(b5); 
		myPack.add(b6); 


		/********************************************************************************************************************************
		 * Auto Generated GUI Stuff
		 */
		setIconImage(Toolkit.getDefaultToolkit().getImage(SixPack.class.getResource("/bottlepacker/resources/Bottle.jpg")));
		setTitle("Bottle Packer");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 423, 603);

		JPanel panel = new JPanel();
		GroupLayout groupLayout_1 = new GroupLayout(getContentPane());
		groupLayout_1.setHorizontalGroup(
				groupLayout_1.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout_1.createSequentialGroup()
						.addContainerGap()
						.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addGap(5))
				);
		groupLayout_1.setVerticalGroup(
				groupLayout_1.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout_1.createSequentialGroup()
						.addGap(6)
						.addComponent(panel, GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE)
						.addContainerGap())
				);


		/********************************************************************************************************************************
		 * creating labels and buttons
		 */

		//Labels
		final JLabel lable_orderNum = new JLabel("Service Order # "+ orderNum);
		JLabel label = new JLabel("");
		JLabel lblCokesAvaliable = new JLabel("Cokes Avaliable _NA_");
		JLabel lblSpriteAvaliable = new JLabel("Sprite Avaliable _NA_");
		


		
		final JLabel lblRightClickTo = new JLabel("Right Click to select soda");

		final JLabel label_bottle1 = new JLabel("");
		final JLabel label_bottle2 = new JLabel("");
		final JLabel label_bottle3 = new JLabel("");
		final JLabel label_bottle5 = new JLabel("");
		final JLabel label_bottle4 = new JLabel("");
		final JLabel label_bottle6 = new JLabel("");

		label_bottle1.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		label_bottle2.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		label_bottle3.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		label_bottle5.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		label_bottle4.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));
		label_bottle6.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));


		//Buttons

		//Place an order, should only 
		final JButton btnPlaceOrder = new JButton("Place Order");


		btnPlaceOrder.setEnabled(false);
		JButton btnReset = new JButton("RESET");
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
				gl_panel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panel.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(lable_orderNum)
								.addComponent(label)
								.addGroup(gl_panel.createSequentialGroup()
										.addGap(1)
										.addComponent(lblCokesAvaliable)
										.addGap(18)
										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
												.addComponent(btnPlaceOrder)
												.addComponent(lblSpriteAvaliable)))
												.addComponent(btnReset)
												.addComponent(lblRightClickTo, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)
												.addGroup(gl_panel.createSequentialGroup()
														.addComponent(label_bottle1)
														.addPreferredGap(ComponentPlacement.UNRELATED)
														.addComponent(label_bottle2))
														.addGroup(gl_panel.createSequentialGroup()
																.addComponent(label_bottle3, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(ComponentPlacement.UNRELATED)
																.addComponent(label_bottle4, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
																.addGroup(gl_panel.createSequentialGroup()
																		.addComponent(label_bottle5, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(ComponentPlacement.UNRELATED)
																		.addComponent(label_bottle6, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)))
																		.addContainerGap(151, Short.MAX_VALUE))
				);
		gl_panel.setVerticalGroup(
				gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
						.addContainerGap()
						.addComponent(lable_orderNum)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(label)
								.addComponent(lblRightClickTo))
								.addPreferredGap(ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
								.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
										.addComponent(label_bottle1)
										.addComponent(label_bottle2))
										.addGap(18)
										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
												.addComponent(label_bottle3, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
												.addComponent(label_bottle4, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
												.addGap(18)
												.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
														.addComponent(label_bottle6, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
														.addComponent(label_bottle5, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
														.addGap(43)
														.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
																.addComponent(btnReset)
																.addComponent(btnPlaceOrder))
																.addPreferredGap(ComponentPlacement.UNRELATED)
																.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
																		.addComponent(lblCokesAvaliable)
																		.addComponent(lblSpriteAvaliable))
																		.addContainerGap())
				);

		/**********************************************************************************************************************************
		 * ACTION Place order button pressed
		 */

		btnPlaceOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				Object[] options = {"Yes, please!",
				"No way!"};
				Component confirmBottles = null;

				int n = JOptionPane.showOptionDialog(
						confirmBottles,
						"Thank you! please confirm the quantity of each brand" + "\n Coca-Cola: " + countCokesOrdered() + "\nSprite: " + countSpritesOrdered() ,
						"Order Confirmation",
						JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE,
						new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/cokesprite.jpg")),     //do not use a custom Icon
						options,  //the titles of buttons
						options[0]); //default button title
				if (n == JOptionPane.YES_OPTION) {





					//Order CONFIRMED This is where were we place our code to send to the robot
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************                	//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************
					//*************************************************************************************************************************






					//Add 1 to the service number and reset the selections
					orderNum++;
					lable_orderNum.setText("Service Order # "+ orderNum);



					//Reset Field for next Order
					label_bottle1.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));		
					label_bottle2.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
					label_bottle3.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
					label_bottle4.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
					label_bottle5.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
					label_bottle6.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	

					numCokesOrdered = 0;
					numSpritesOrdered = 0;

					for (int i = 0; i < myPack.size() ; ++i){

						Bottle item = myPack.get(i);

						String theFlavor = item.getBrand();

						item.setBrand("none");
					}

					btnPlaceOrder.setEnabled(false);


				} else if (n == JOptionPane.NO_OPTION) {
					//do nothing
				} else {
					//do nothing
				}
			}

		});




		/********************************************************************************************************************
		 * ACTION RESET BUTTON
		 */
		btnReset.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				label_bottle1.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));		
				label_bottle2.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
				label_bottle3.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
				label_bottle4.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
				label_bottle5.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	
				label_bottle6.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/plainBottle.jpg")));	

				numCokesOrdered = 0;
				numSpritesOrdered = 0;

				for (int i = 0; i < myPack.size() ; ++i){

					Bottle item = myPack.get(i);

					String theFlavor = item.getBrand();

					item.setBrand("none");
				}

				btnPlaceOrder.setEnabled(false);

			}
		});


		/*******************************************************************************************************************************
		 * Auto Generated properties
		 */
		JPopupMenu popBottle1 = new JPopupMenu();
		JPopupMenu popBottle2 = new JPopupMenu();
		JPopupMenu popBottle3 = new JPopupMenu();
		JPopupMenu popBottle4 = new JPopupMenu();
		JPopupMenu popBottle5 = new JPopupMenu();
		JPopupMenu popBottle6 = new JPopupMenu();


		addPopup(label_bottle1, popBottle1);
		addPopup(label_bottle2, popBottle2);
		addPopup(label_bottle3, popBottle3);
		addPopup(label_bottle4, popBottle4);
		addPopup(label_bottle5, popBottle5);
		addPopup(label_bottle6, popBottle6);

		JMenuItem popBottle1_coke = new JMenuItem("");
		JMenuItem popBottle2_coke = new JMenuItem("");
		JMenuItem popBottle3_coke = new JMenuItem("");
		JMenuItem popBottle4_coke = new JMenuItem("");
		JMenuItem popBottle5_coke = new JMenuItem("");
		JMenuItem popBottle6_coke = new JMenuItem("");

		JMenuItem popBottle1_sprite = new JMenuItem("");
		JMenuItem popBottle2_sprite = new JMenuItem("");
		JMenuItem popBottle3_sprite = new JMenuItem("");
		JMenuItem popBottle4_sprite = new JMenuItem("");
		JMenuItem popBottle5_sprite = new JMenuItem("");
		JMenuItem popBottle6_sprite = new JMenuItem("");

		popBottle1_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle2_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle3_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle4_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle5_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
		popBottle6_coke.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));

		popBottle1.add(popBottle1_coke);
		popBottle2.add(popBottle2_coke);
		popBottle3.add(popBottle3_coke);
		popBottle4.add(popBottle4_coke);
		popBottle5.add(popBottle5_coke);
		popBottle6.add(popBottle6_coke);

		popBottle1.add(popBottle1_sprite);
		popBottle2.add(popBottle2_sprite);
		popBottle3.add(popBottle3_sprite);
		popBottle4.add(popBottle4_sprite);
		popBottle5.add(popBottle5_sprite);
		popBottle6.add(popBottle6_sprite);


		popBottle1_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle2_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle3_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle4_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle5_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
		popBottle6_sprite.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));

		panel.setLayout(gl_panel);
		getContentPane().setLayout(groupLayout_1);




		/******************************************************************************************************************************************
		 * Pop up bottle 1
		 * 
		 */

		/**
		 * Action selects coke bottle
		 */
		popBottle1_coke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b1.setBrand("coke");
				b1.setLocation(1);

				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){

					btnPlaceOrder.setEnabled(true);

				}

				label_bottle1.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
			}
		});


		/**
		 * Action selects Sprite bottle
		 */
		popBottle1_sprite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {;

			b1.setBrand("sprite");
			b1.setLocation(1);


			//Check if all bottles have been ordered
			if (countBottlesOrdered() == 6){
				btnPlaceOrder.setEnabled(true);

			}
			label_bottle1.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
			}
		});


		/******************************************************************************************************************************************
		 * Pop up bottle 2
		 * 
		 */

		/**
		 * Action selects coke bottle
		 */
		popBottle2_coke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b2.setBrand("coke");
				b1.setLocation(2);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle2.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));

			}
		});

		/**
		 * Action selects Sprite bottle
		 */
		popBottle2_sprite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b2.setBrand("sprite");
				b1.setLocation(2);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle2.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
			}
		});


		/******************************************************************************************************************************************
		 * Pop up bottle 3
		 * 
		 */

		/**
		 * Action selects coke bottle
		 */
		popBottle3_coke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b3.setBrand("coke");
				b1.setLocation(3);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle3.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
			}
		});

		/**
		 * Action selects Sprite bottle
		 */
		popBottle3_sprite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b3.setBrand("sprite");
				b1.setLocation(3);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle3.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
			}
		});

		/******************************************************************************************************************************************
		 * Pop up bottle 4
		 * 
		 */
		/**
		 * Action selects coke bottle
		 */
		popBottle4_coke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b4.setBrand("coke");
				b1.setLocation(4);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle4.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
			}
		});

		/**
		 * Action selects Sprite bottle
		 */
		popBottle4_sprite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b4.setBrand("sprite");
				b1.setLocation(4);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle4.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
			}
		});




		/******************************************************************************************************************************************
		 * Pop up bottle 5
		 * 
		 */

		/**
		 * Action selects coke bottle
		 */
		popBottle5_coke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b5.setBrand("coke");
				b1.setLocation(5);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle5.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
			}
		});

		/**
		 * Action selects Sprite bottle
		 */
		popBottle5_sprite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent	arg0) {
				b5.setBrand("sprite");

				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle5.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
			}
		});


		/******************************************************************************************************************************************
		 * Pop up bottle 6
		 * 
		 */
		/**
		 * Action selects coke bottle
		 */
		popBottle6_coke.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				b6.setBrand("coke");
				b1.setLocation(6);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle6.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/coke-coca-cola.jpg")));
			}
		});

		/**
		 * Action selects Sprite bottle
		 */
		popBottle6_sprite.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent	arg0) {
				b6.setBrand("sprite");
				b1.setLocation(6);


				//Check if all bottles have been ordered
				if (countBottlesOrdered() == 6){
					System.out.println("Im here");
					btnPlaceOrder.setEnabled(true);

				}

				label_bottle6.setIcon(new ImageIcon(SixPack.class.getResource("/bottlepacker/resources/SPRITE.png")));
			}
		});






		/******************************************************************************************************************************************
		 * Menu Bar
		 */
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);

		JMenuItem mntmExit = new JMenuItem("Exit");
		mnFile.add(mntmExit);

		JMenu mnAbout = new JMenu("Info");
		menuBar.add(mnAbout);

		JMenuItem mntmInstructions = new JMenuItem("Instructions");
		mntmInstructions.addActionListener(new ActionListener() {


			// If the Instructions tab is hit 
			public void actionPerformed(ActionEvent arg0) {

				Component instructionsFrame = null;
				// Display instructions
				JOptionPane.showMessageDialog(instructionsFrame,
						"Right click on one of the 6 icons to select your desired bevrege" +
								"\n once all 6 icons have been filled place your order by clicking the _Place Order_ Button" +
						"\n After confirming, the robot will create your desired 6 pack in the order as shown on the screen");



			}
		});
		mnAbout.add(mntmInstructions);

		JMenuItem mntmAbout = new JMenuItem("About");
		mntmAbout.addActionListener(new ActionListener() {


			// If the about tab is hit
			public void actionPerformed(ActionEvent e) {


				Component infoFrame = null;
				//Display Names, Project Title , ect.
				JOptionPane.showMessageDialog(infoFrame,
						"This project was created by Group 8 for Professor Putnams ME/RBE 4815 Industrial Robotics Class" +
								"\n Project Finialized: 2/25/2013" +
								"\n" +
								"\n Members include:" +
								"\n Eric Cobane" +
								"\n Ryan Giovacchini" +
								"\n Jeremy Lowrey" +
								"\n Anselm Mak" +
						"\n Matthew Tatro");





			}
		});
		mnAbout.add(mntmAbout);
	}

	/**
	 * Creates popup Window
	 * @param component
	 * @param popup
	 */
	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}

	/********************************************************************************************************************
	 * countBottlesOrdered
	 */

	public int countBottlesOrdered(){ 

		numDrinks = 0;
		for (int i = 0; i < myPack.size() ; ++i){

			Bottle item = myPack.get(i);
			String theFlavor = item.getBrand();

			if (item.getBrand().equals("coke")||item.getBrand().equals("sprite"))	{
				numDrinks++;
			}
		}
		return numDrinks;

	}

	/********************************************************************************************************************
	 * countCokesOrdered
	 */

	public int countCokesOrdered(){ 

		numCokesOrdered = 0;
		for (int i = 0; i < myPack.size() ; ++i){

			Bottle item = myPack.get(i);
			String theFlavor = item.getBrand();

			if (item.getBrand().equals("coke")){
				numCokesOrdered++;
			}
		}
		return numCokesOrdered;

	}

	/********************************************************************************************************************
	 * countSpritesOrdered
	 */

	public int countSpritesOrdered(){ 

		numSpritesOrdered = 0;
		for (int i = 0; i < myPack.size() ; ++i){

			Bottle item = myPack.get(i);
			String theFlavor = item.getBrand();

			if (item.getBrand().equals("sprite")){
				numSpritesOrdered++;
			}
		}
		return numSpritesOrdered;

	}

	/********************************************************************************************************************
	 * countSpritesOrdered
	 */

	public void fromSensor(){ 

		// Add sensor readings here, ultrasonic having problems problems reaading from cylindrical shape
		//Will be continued pending time left
	}
}




